import numpy as np
import lazy_property
from scipy.stats import norm
from functools import reduce
from operator import add

from .data_helper import cols_by_date, list_dates
from .data_helper import filter_data, date_to_str
from .likelihood import Likelihood


def get_cols_over_time(col_fmt='payments_by_{}'):
    return [col_fmt.format(date_to_str(d)) for d in Likelihood.event_dates]


def plot_over_time(df, col_fmt='payments_by_{}', func=np.sum, ax=None, linestyle='solid', normalize=None):
    cols = get_cols_over_time(col_fmt)
    this_df = df[cols]
    this_df.columns = Likelihood.event_dates
    if normalize:
        this_df = np.divide(this_df, normalize)
    ax = this_df.apply(func, axis=0).plot(ax=ax, linestyle=linestyle)
    return ax


payment_cols = get_cols_over_time()
priority_cols = get_cols_over_time('priority_by_{}')
action_cols = get_cols_over_time('action_by_{}')
relative_payment_cols = ['relative_' + c for c in payment_cols]
fwdiff_payment_cols = ['fwdiff_' + p for p in payment_cols]
binary_fwdiff_payment_cols = ['binary_fwdiff_' + p for p in payment_cols]
relative_fwdiff_payment_cols = ['relative_' + c for c in fwdiff_payment_cols]
action_nomedida_cols = get_cols_over_time('action_no_medida_by_{}')
G2G1_nopayment = get_cols_over_time('G2_nopayment_by_{}')
cumul_binary_fwdiff_payment_cols = ['cumul_binary_' + c for c in fwdiff_payment_cols]
